﻿using Admin.Core.Common.Output;
using Admin.Core.Service.Admin.Department;
using Admin.Core.Service.Admin.Department.Input;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Admin.Core.Controllers.Admin
{
    /// <summary>
    /// 部门管理
    /// </summary>
    public class DepartmentController : AreaController
    {
        private readonly IDepartmentService _DepartmentService;

        public DepartmentController(IDepartmentService DepartmentService)
        {
            _DepartmentService = DepartmentService;
        }

        /// <summary>
        /// 查询单条部门
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IResponseOutput> Get(long id)
        {
            return await _DepartmentService.GetAsync(id);
        }

        /// <summary>
        /// 查询部门列表
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> GetList(string key)
        {
            return await _DepartmentService.GetListAsync(key);
        }

        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IResponseOutput> Add(DepartmentAddInput input)
        {
            return await _DepartmentService.AddAsync(input);
        }

        /// <summary>
        /// 修改部门
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IResponseOutput> Update(DepartmentUpdateInput input)
        {
            return await _DepartmentService.UpdateAsync(input);
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IResponseOutput> SoftDelete(long id)
        {
            return await _DepartmentService.SoftDeleteAsync(id);
        }
    }
}